<?php
class SlugComponent {
	function createSlug($str, $createTime = null) {
		if (! $str) {
			return $str;
		}
		
		$str = strtolower($str);
		$str = preg_replace('#[^a-z0-9\-]#im', "_", $str);
		
		$str = preg_replace('#_+#', "_", $str);
		$str = preg_replace('#^_+#', "", $str);
		$str = preg_replace('#_+$#', "", $str);
		
		$createTime = $createTime ? $createTime : time();
		$createTime = date("YmdHis", $createTime);
		
		return $createTime. "-". $str;
	}
}
?>